/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import entities.Applicant;
import entities.Application;
import entities.Application.Evaluation;
import entities.Application.Status;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import persistence.GenericDAO;
import persistence.GenericDAOImpl;

/**
 *
 * @author akefeli
 */
@Stateless
@LocalBean
public class StaffControllerEJB {

    private Application application;
    private Applicant applicant;
    public Applicant findApplicant(String email) {
        application = null;
        applicant = null;
        GenericDAO<Applicant, Long> dao = new GenericDAOImpl(Applicant.class);
        List<Applicant> apps = dao.findAll();
        for (Applicant app : apps) {
            if (app.getEmail().equals(email)) {
                applicant = app;
                application = app.getApplication();
            }
        }
        return applicant;
    }

    public Status getStatus() {
        if (application != null) {
            return application.getStatus();
        } else {
            return null;
        }
    }

    public void overrideStatus(Status status) {
        if (this.application != null) {
            this.application.setStatus(status);
            GenericDAO<Application, Long> dao = new GenericDAOImpl(Application.class);
            dao.update(application);
        }
    }
    public void overrideEvaluation(Evaluation evaluation) {
        if (this.application != null) {
            this.application.setEvaluation(evaluation);
            GenericDAO<Application, Long> dao = new GenericDAOImpl(Application.class);
            dao.update(application);
        }
    }
    
    public Evaluation getEvaluation(){
        if (application != null) {
            return application.getEvaluation();
        } else {
            return null;
        }
    }
    
    public void setEvaluation(Evaluation evaluation){
        if (this.application != null) {
            this.application.setEvaluation(evaluation);
        }
    }

    public Applicant getApplicant() {
        return applicant;
    }

    public Application getApplication() {
        return application;
    }
    
    
}
